﻿using DTCash.Logger;
using DTCash.Logger.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTCash.Redis;
using Uranus.Service.EmployeeService;

namespace Uranus.Service
{
    public class Employee : BaseData
    {

        private static Employee employee = null;

        public static Employee GetEmployee()
        {
            if (employee == null)
            {
                employee = new Employee();
            }
            return employee;
        }


        /// <summary>
        /// 获取广告列表
        /// </summary>
        /// <param name="adRequest"></param>
        /// <returns></returns>
        public AdResponse GetAdDTOList(AdRequest adRequest)
        {
            EmployeeServiceClient employeeServiceClient = new EmployeeServiceClient();
            try
            {
                Func<AdResponse> method = delegate
                {
                    AdResponse response = employeeServiceClient.GetAdDTOList(adRequest);
                    return response.Code == 2 ? null : response;
                };
                return GetData<AdResponse>(method, CacheItem.InitByIdentity(adRequest.AdTypeId.ToString(), adRequest.PageIndex, adRequest.PageSize).AD.Info) ?? new AdResponse();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogEnum.Error, "获取广告列表 GetAdDTOList", ex.Message.ToString(), adRequest);
                return new AdResponse();
            }
            finally
            {
                employeeServiceClient.Close();
            }
        }
    }

}
